//
//  NSMutableAttributedString+GDAttString.m
//  GuDou
//
//  Created by mac on 2016/12/27.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "NSMutableAttributedString+GDAttString.h"

@implementation NSMutableAttributedString (GDAttString)
+ (NSMutableAttributedString *)arrtLabelText:(NSString *)text arrFont:(UIFont *)attFont attColor:(UIColor *)attColor lineLengh:(CGFloat)lineLengh alignment:(NSInteger)alignment colorLenghFrom:(NSInteger)colorLenghFrom  colorLengh:(NSInteger)colorLengh
{
    
    if (text.length == 0){
        text = @"";
    }
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text];
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.alignment = alignment;
    style.lineSpacing = lineLengh;
    [attr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
    [attr addAttribute:NSFontAttributeName value:attFont range:NSMakeRange(0, text.length)];
    [attr addAttribute:NSForegroundColorAttributeName value:attColor range:NSMakeRange(colorLenghFrom, colorLengh)];
    return attr;
}

+ (NSAttributedString *) attStringFromTextForChatting:(NSString *) aInputText textFont:(UIFont*)font
{
    
    if(!aInputText.length){
        aInputText = @"";
    }
    
    NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:aInputText];
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:8];
    
    [string addAttribute:NSParagraphStyleAttributeName
                   value:paragraphStyle
                   range:NSMakeRange(0, string.length)];
    if (font) {
        [string addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, string.length)];
    }
    return string;
}


@end
